---
description: "Reference for Nitric's v0 Go library - Write a file to a bucket."
---

# Go - Bucket.File.Write()

Write a file to a bucket.

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  bucket, err := nitric.NewBucket("bucket-name").With(nitric.BucketWriting)
  if err != nil {
    return
  }

  err := bucket.File("cat.png").Write(context.TODO(), []byte("contents"))
  if err != nil {
    return
  }

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="ctx" required type="context">
    The context of the call, used for tracing.
  </Property>
  <Property name="data" required type="[]byte">
    The data to write to the file.
  </Property>
</Properties>

## Examples

### Write a file

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  bucket, err := nitric.NewBucket("bucket-name").With(nitric.BucketWriting)
  if err != nil {
    return
  }

  err := bucket.File("cat.png").Write(context.TODO(), []byte("contents"))
  if err != nil {
    return
  }

  nitric.Run()
}
```
